<?php
class Weblog extends CI_Controller {
	public function __construct() {
		parent::__construct();
		$this -> output -> enable_profiler(PROFILER);		$this -> em = $this -> doctrine -> em;
	}	public function index() {						$data['pageTitle']="EthicalCoder | Raul Ivan Garcia Valdivia - WebBlog, Simple HTML5 tutorials, jQuery Examples, CSS , Web Design, Information Technology News";				
		$qb = $this -> em -> createQueryBuilder();		$qb -> add('select', 'c') -> add('from', 'models\Post c');		$qb -> add('orderBy', 'c.id DESC');		$postResult = $qb -> getQuery() -> getResult();		$posts = !empty($postResult) ? $postResult : NULL;		$data['main_content'] = "public/weblog/index";
		$data['posts'] = $posts;
		$this -> load -> view("public/template", $data);
	}	public function add_comment() {		$post = $this -> em -> find('models\Post', $this -> input -> post('post_id'));		$participant = new models\Participant();		try {			$this -> em -> persist($participant);			$this -> em -> flush();		} catch(Exception $e) {			redirect('weblog/sorry');		}		models\Participant::prepareData($_POST, $participant);		$comment = new models\Comment($post, $participant);		models\Comment::prepareData($_POST, $comment);		try {			$this -> em -> persist($comment);			$this -> em -> flush();			redirect('weblog/index#comment' . $comment -> getId());		} catch(Exception $e) {
			redirect('weblog/sorry');
		}	}	public function read() {		if ($this -> uri -> segment(3)) {			$_postCleanTitle = $this -> uri -> segment(3);			$_foundPost = $this -> em -> getRepository('models\Post') -> findOneBy(array('title_clean' => $_postCleanTitle));			$data['pageTitle']=$_foundPost->getTitle();				$data['pageDescription']="Raul-Ivan.com - ".$_foundPost->getTitle();				$data['post'] = $_foundPost;			$data['main_content'] = "public/weblog/read";			$this -> load -> view("public/template", $data);		}	}	public function category() {		if ($this -> uri -> segment(3)) {			$_postCategoryNameClean= $this -> uri -> segment(3);						$_category = $this -> em -> getRepository('models\Category') -> findOneBy(array('name_clean' => $_postCategoryNameClean));						$data['pageTitle']=$_category->getName();			$data['pageDescription']="Raul-Ivan.com - ".$_category->getName();						$_foundPosts = $this -> em -> getRepository('models\Post') -> findBy(array('category' => $_category->getId()));			$data['posts'] = $_foundPosts;			$data['main_content'] = "public/weblog/categorylist";			$this -> load -> view("public/template", $data);		}	}	public function sorry() {		$data['main_content'] = "public/weblog/sorry";		$this -> load -> view("public/template", $data);	}}?>